@extends('layouts.admin')
@section('resources')
    <script src="{{asset('public/resources/layer-v3.0.2/layer/layer.js')}}"></script>
    @endsection
@section('content')
    <!--面包屑导航 开始-->
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="{{url('Admin/info')}}">首页</a> &raquo; <a href="{{url('Admin/config')}}">网站配置</a> &raquo; 所有配置
    </div>
    <!--面包屑导航 结束-->

	<!--结果页快捷搜索框 开始-->

    <!--结果页快捷搜索框 结束-->

    <!--搜索结果页面 列表 开始-->
    <form action="{{url('Admin/configWrite')}}" method="post">
        <div class="result_wrap">
            <!--快捷导航 开始-->
            <div class="result_content">
                <div class="short_wrap">
                    <a href="{{url('Admin/config/create')}}"><i class="fa fa-plus"></i>新增配置</a>
                    {{--<a href="#"><i class="fa fa-recycle"></i>批量删除</a>--}}
                    <a href="{{url('Admin/config')}}"><i class="fa fa-refresh"></i>更新排序</a>
                </div>
            </div>
            <!--快捷导航 结束-->
        </div>
        @if(isset($msg))
        <div style="margin: 8px 22px;border:dotted 1px goldenrod;padding: 8px;border-radius: 6px">
            <p style="color: red">{{$msg}}</p>

        </div>
        @endif
        <div class="result_wrap">
            <div class="result_content">
                <table class="list_tab">
                    <tr>

                        <th class="tc" width="5%">排序</th>
                        <th class="tc">ID</th>
                        <th>配置标题</th>
                        <th>配置名称</th>
                        <th>类型值</th>
                        <th>操作</th>
                    </tr>
                    @foreach($list as $k=>$v )
                    <tr id="item{{$v['conf_id']}}">
                        <input type="hidden" name="conf_id[]" value="{{$v->conf_id}}">
                        <td class="tc">
                            <input type="text" name="ord[]" value="{{$v['sort']}}" onchange="linkOrder(this,{{$v->conf_id}})">
                        </td>
                        <td class="tc">{{$v['conf_id']}}</td>
                        <td>
                            <a href="#">{{$v['conf_title']}}</a>
                        </td>
                        <td class="tc">{{$v['conf_name']}}</td>
                        <td>{!!$v['html']!!}</td>
                        <td>
                            {{--<a href="{{url('Admin/category/add_sub?'.$v->cate_id)}}">添加子分类</a>--}}
                            <a href="{{url('Admin/config/'.$v->conf_id.'/edit')}}">修改</a>
                            <a href="javascript:;" onclick="destroy({{$v['conf_id']}})">删除</a>
                        </td>
                    </tr>
                   @endforeach
                </table>

            </div>
        </div>

        <div style="margin-top: 12px;text-align: center">

            <input type="submit" value='保存'>
            <input type="button" class="back" onclick="history.go(-1)" value="返回">

        </div>

        {{csrf_field()}}
    </form>

    <!--搜索结果页面 列表 结束-->
    <script>
        function destroy(id) {
         var token =  $("input[name='_token']").val();
         var item = $("#item"+id);
         layer.confirm('确定删除吗',{
           btn:['确定','取消']
         },function () {
             $.post("{{url('Admin/config/')}}/"+id,{"_method":"delete",'_token':token},function (data) {
                 if(data.code == 0){
                     time:2000,
                     layer.msg(data.msg,{icon:1})
                     item.remove();
                 }else {
                     layer.msg(data.msg, {icon: 2})
                 }
                 });
         },
             function () {
             // layer.msg('',{icon:1})
             }
         )
        }

        function linkOrder(obj,id) {
          var token =  $("input[name='_token']").val();
          var order = $(obj).val();
          $.post(
              "{{url('Admin/confOrder')}}",
              {'_token':token,"conf_id":id,"conf_order":order},
              function (data) {
               if(data.code == 0){
                   layer.msg(data.msg,{icon:1});
               }else{
                   layer.msg(data.msg,{icon:2});
               }
              }
          );
        }
    </script>
@endsection